/* 封装一个指令用以实现textarea文本框的提示语 */
class textareaTitle{
    constructor() {
        this.restrict = 'A';
        this.require  = 'ngModel';
    }

    link(scope, ele, attrs, modelController) {
        var text        = attrs.textareaTitle,
            placeholder = attrs.placeholder,
            alltext     = text + placeholder;

        ele.attr('placeholder', alltext);
        ele.on('focus', () => {
            if (!modelController.$modelValue) {
                setVal(text);
            }
            scope.$apply();
        });
        ele.on('blur', () => {
            if (modelController.$modelValue === text) {
                setVal('');
            }
        });
        var setVal = (v) => {
            modelController.$setViewValue(v);
            modelController.$render();
        }
    }
}

export default textareaTitle;